/**
 * 
 */
package com.piz.web.product;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;

import com.piz.model.ItemClassification;


/**
 * @author Administrator
 *
 */
@Component("productCategoryValidation")
public class ProductCategoryValidation {
	
	public boolean supports(Class<?> klass) {
		return ItemClassification.class.isAssignableFrom(klass);
	}
	
	public void validate(Object target, Errors errors) 
	{
		ItemClassification itemClassification = (ItemClassification) target;
			if(itemClassification.getName() == null || itemClassification.getName().equals(""))
			{
				errors.rejectValue("name",
						"",
						"Category Name is required");
			}
		
			if(itemClassification.getActive() == null)
			{
				errors.rejectValue("active",
						"",
						"Active is required");
			}
			
		  if(itemClassification.getFile().getSize()==0){
			   errors.rejectValue("file", "error.empty.file", "Please Select File.");
			}
		  if(itemClassification.getFile().getSize() > 30000){
			   errors.rejectValue("file", "error.empty.file", "File size more than 30 KB ");
			}
	}
		
	

}
